% TODO proof-reading
\subsubsection{Второй пример}

Еще один пример:

\begin{lstlisting}[style=customjava]
public class strings
{
	public static char test (String a)
	{
		return a.charAt(3);
	};

	public static String concat (String a, String b)
	{
		return a+b;
	}
}
\end{lstlisting}

\begin{lstlisting}
  public static char test(java.lang.String);
    flags: ACC_PUBLIC, ACC_STATIC
    Code:
      stack=2, locals=1, args_size=1
         0: aload_0       
         1: iconst_3      
         2: invokevirtual #2        // Method java/lang/String.charAt:(I)C
         5: ireturn       
\end{lstlisting}
         

Складывание строк происходит при помощи класса \TT{StringBuilder}:

\begin{lstlisting}
  public static java.lang.String concat(java.lang.String, java.lang.String);
    flags: ACC_PUBLIC, ACC_STATIC
    Code:
      stack=2, locals=2, args_size=2
         0: new           #3        // class java/lang/StringBuilder
         3: dup           
         4: invokespecial #4        // Method java/lang/StringBuilder."<init>":()V
         7: aload_0       
         8: invokevirtual #5        // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
        11: aload_1       
        12: invokevirtual #5        // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
        15: invokevirtual #6        // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
        18: areturn       
\end{lstlisting}

Еще пример:

\begin{lstlisting}[style=customjava]
	public static void main(String[] args)
	{
		String s="Hello!";
		int n=123;
		System.out.println("s=" + s + " n=" + n);
	}
\end{lstlisting}


И снова, строки создаются используя класс \TT{StringBuilder} и его метод \TT{append},
затем сконструированная строка передается в метод \TT{println}:

\begin{lstlisting}
  public static void main(java.lang.String[]);
    flags: ACC_PUBLIC, ACC_STATIC
    Code:
      stack=3, locals=3, args_size=1
         0: ldc           #2        // String Hello!
         2: astore_1      
         3: bipush        123
         5: istore_2      
         6: getstatic     #3        // Field java/lang/System.out:Ljava/io/PrintStream;
         9: new           #4        // class java/lang/StringBuilder
        12: dup           
        13: invokespecial #5        // Method java/lang/StringBuilder."<init>":()V
        16: ldc           #6        // String s=
        18: invokevirtual #7        // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
        21: aload_1       
        22: invokevirtual #7        // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
        25: ldc           #8        // String  n=
        27: invokevirtual #7        // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
        30: iload_2       
        31: invokevirtual #9        // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
        34: invokevirtual #10       // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
        37: invokevirtual #11       // Method java/io/PrintStream.println:(Ljava/lang/String;)V
        40: return        
\end{lstlisting}
